<template>
	<view>
		<!-- 	//https://unicloud-api.dcloud.net.cn/unicloud/api/file/upload-info?spaceId=432615d7-fcd2-498d-8daa-8ad3a1ce4d8b&appid=&provider=aliyun&name=1.jpg&size=61754
		请求方法: GET -->
		<lg-edit showImgSize showImgToolbar showImgResize placeholder="请输入内容" filePrefix="redactor" @editOk="editOk"></lg-edit>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
import { addDemand } from '../../services/issue/index.js';
import { mapGetters, mapMutations } from 'vuex';
export default {
	data() {
		return {};
	},
	computed: {
		...mapGetters({
			userInfo: 'user/info',
			hasLogin: 'user/hasLogin'
		})
	},
	methods: {
		async editOk({ html = '' }) {
			if (html) {
				// 保存
				const {
					avatar_file: { url: avatar },
					_id: id,
					nickname,
					username
				} = this.userInfo;
				const {result:{id:resId}} = await this.$db.collection('lg-demand').add({
					creator: {
						id, //用户id
						nickname, // 昵称
						username, // 名称
						avatar // 头像地址
					},
					content: html
				});
				
				if(resId){
					this.$refs.uTips.show({
						title: '新增成功',
						type: 'success ',
						duration: '3000'
					});
					// 跳转
					this.$u.route({
						type:"back"
					})
				}else{
					this.$refs.uTips.show({
						title: '新增错误',
						type: 'error',
						duration: '3000'
					});
					
				}

			} else {
				this.$refs.uTips.show({
					title: '内容不能为空',
					type: 'error',
					duration: '3000'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped></style>
